<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        v-model="form"
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :permission="permissionList"
        :upload-preview="uploadPreview">
        <template slot-scope="scope" slot="menuLeft">
        <el-button type="primary" size="small" @click.stop="handleExport">导 出</el-button>
        <el-button type="primary" size="small" :hidden="true" v-if="false" @click.stop="handlePrint">打 印</el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button
            :type="scope.type"
            :size="scope.size"
            v-if="scope.row.isReceive =='否'"
            @click.stop="LingYong(scope.row)"
          >领用</el-button>
        </template>
      </avue-crud>
    </basic-container>
    <open-dialog :DialogVisible.sync="LingYongVisDialog" title="领用" width="80%">
      <el-form label-width="60px">
        <avue-form v-model="form" :option="tableOptionLingYong" style="margin-bottom:40px;"></avue-form>
        <div class="bottom-menu-ticket-receive">
          <el-button type="primary" @click="edit">确认</el-button>
          <el-button type="primary" @click="LingYongVisDialog=false">取消</el-button>
        </div>
      </el-form>
    </open-dialog>
  </div>
</template>

<script>
import baseCrud from '@/mixins/base-crud'
import {
  fetchList,
  getObj,
  addObj,
  putObj,
  delObj,
  exportExcel,
} from "@/api/subway/swtkticketreceive";
import { tableOption,tableOptionLingYong,startDate, endDate } from "@/const/crud/subway/swtkticketreceive";

export default {
  name: "swtkticketreceive",
  mixins: [baseCrud('subway/swtkticketreceive')],
  data() {
    return {
      exportName: '车票领用.xlsx',
      tableOptionLingYong:tableOptionLingYong,
      LingYongVisDialog:false,
      searchForm: {
        dates1: [startDate, endDate]
      }
    }
  },
  computed: {
    permissionList() {
      return {
        addBtn: this.vaildData(this.permissions.st_ticket_receive_add, false),
        delBtn: this.vaildData(
          this.permissions.st_ticket_receive_delete,
          false
        ),
        editBtn: this.vaildData(
          this.permissions.st_ticket_receive_update,
          false
        ),
      };
    },
  },
  methods: {
    getList(page) {
      this.tableLoading = true
      return fetchList(Object.assign({
        current: page.currentPage,
        size: page.pageSize
      }, this.params, this.searchForm)).then(response => {
        this.tableData = response.data.data.records
        this.tableData.forEach(row => {
          row.stockArea = Number(row.stockArea)
        })
        this.page.total = response.data.data.total
        this.tableLoading = false
      })
    },
    edit(){
       putObj(this.form)
        .then((data) => {
          this.LingYongVisDialog = false;
          this.$message.success("领用成功");
          this.getList(this.page);
        })
        .catch(() => {
          loading();
        });
    },
    LingYong(row){
      this.form=row;
      if(this.form.receiverId==null || this.form.receiverId==''){
         this.form.receiverId = this.form.outputPersonCode;
         this.form.receiverName = this.form.outputPersonName;
      }
       this.LingYongVisDialog=true;
    },
    uploadPreview(file, column, done) {
      console.log(file, column);
      console.log(file.url);
      var strRegex = "(.jpg|.png|.jpeg)$";
      var re = new RegExp(strRegex);
      if (!re.test(file.url)) {
        window.location.href = file.url;
      } else {
        window.location.href = file.url;
        done();
      }
    }
  }
}
</script>

<style lang="scss">
.header {
  margin: 0 auto;
  width: 99%;
  padding: 5px 10px;
  border: 1px solid #e4e4e4;
  border-bottom: none;
  background-color: #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.bottom-menu-ticket-receive {
  margin-top: 48px;
  text-align: center;
}
</style>
